#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <climits>
#define int long long 
#define x first 
#define y second 
#define ct cout
using namespace std ;
typedef pair<int,int> PII;
const int N = 1e5 + 10;
int a[N];
PII p[N];
void solve()
{
   int x,y,k;
   cin >> x >> y >> k;
   int ans = y * k;
   if(x >= ans)  ct << x - ans << endl;
   else  
   {
       int c = x / y;
       k -= c;
       x %= y;
       if(k % 2) ct << abs(x - y) << endl;
       else ct << x << endl;
   }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t ;
    cin >> t;
    while(t -- ) solve();
    return 0;
}